use crate::sublist;

#[derive(Debug, PartialEq, Eq)]
pub enum Comparison {
    Equal,
    Sublist,
    Superlist,
    Unequal,
}

pub fn sublist<T: PartialEq>(_first_list: &[T], _second_list: &[T]) -> Comparison {
    if _first_list == _second_list {
        Comparison::Equal
    } else {
        if _first_list.len() == _second_list.len() {
            Comparison::Unequal
        } else if _first_list.len() < _second_list.len() {
            let mut count = 0;
            for i in 0..=_second_list.len() - _first_list.len() {
                for j in 0.._first_list.len() {
                    let t1 = _first_list.get(j).unwrap();
                    let t2 = _second_list.get(i + j).unwrap();
                    if t1 != t2 {
                        count += 1;
                        break;
                    }
                }
            }
            if count <= (_second_list.len() - _first_list.len()) { Comparison::Sublist } else { Comparison::Unequal }
        } else {
            let mut count = 0;
            for i in 0..=_first_list.len() - _second_list.len() {
                for j in 0.._second_list.len() {
                    let t1 = _second_list.get(j).unwrap();
                    let t2 = _first_list.get(i + j).unwrap();
                    if t1 != t2 {
                        count += 1;
                        break;
                    }
                }
            }
            if count <= (_first_list.len() - _second_list.len()) { Comparison::Superlist } else { Comparison::Unequal }
        }
    }
}

#[test]
#[ignore]
fn at_start_of_superlist() {
    let list_one: &[i32] = &[0, 1, 2, 3, 4, 5];
    let list_two: &[i32] = &[0, 1, 2];
    let output = sublist::sublist(list_one, list_two);
    let expected = Comparison::Superlist;
    assert_eq!(output, expected);
}